local extension = Package("aaa_steam_offcl")
extension.extensionName = "aaa_steam"

local U = require "packages/utility/utility"
local RUtil = require "packages/aaa_fenghou/utility/rfenghou_util"
local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
  ["aaa_steam_offcl"] = "官！",
}


local liuyong = General(extension, "steam__liuyong", "han", 3)
local zhuning = fk.CreateActiveSkill{
  name = "steam__zhuning",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  prompt = "#zhuning",
  can_use = function(self, player)
    if not player:isNude() then
      if player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 then
        return true
      elseif player:usedSkillTimes(self.name, Player.HistoryPhase) == 1 then
        return player:getMark("zhuning-phase") > 0
      end
    end
  end,
  card_filter = Util.TrueFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:moveCardTo(effect.cards, Card.PlayerHand, target, fk.ReasonGive, self.name, "", false, player.id, "@@zhuning-inhand")
    if not player.dead then
      local cards = table.filter(U.getUniversalCards(room, "bt", false), function (id)
        return Fk:getCardById(id).is_damage_card
      end)
      local use = U.askForUseRealCard(room, player, cards, nil, self.name, "#zhuning-use",
        {expand_pile = cards, bypass_times = true}, true, true)
      if use then
        local use = {
          card = Fk:cloneCard(use.card.name),
          from = player.id,
          tos = use.tos,
          extraUse = true,
        }
        use.card.skillName = self.name
        room:useCard(use)
        if not player.dead and not use.damageDealt then
          room:setPlayerMark(player, "zhuning-phase", 1)
        end
      end
    end
  end,
}
local function getFengxiangPlayer(room)
  local nums = table.map(room.alive_players, function(p)
    return #table.filter(p:getCardIds("h"), function(id)
      return Fk:getCardById(id, true):getMark("@@zhuning-inhand") > 0
    end)
  end)
  local n = math.max(table.unpack(nums))
  if #table.filter(room.alive_players, function(p)
      return #table.filter(p:getCardIds("h"), function(id)
        return Fk:getCardById(id, true):getMark("@@zhuning-inhand") > 0
      end) == n
    end) > 1 then
      return 0
  else
    return room.alive_players[table.indexOf(nums, n)].id
  end
end
local fengxiang = fk.CreateTriggerSkill{
  name = "steam__fengxiang",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.Damaged, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.Damaged then
        return target == player
      else
        local to = getFengxiangPlayer(player.room)
        for _, move in ipairs(data) do
          if move.extra_data and move.extra_data.fengxiang and move.extra_data.fengxiang ~= to then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local to = getFengxiangPlayer(room)
      if to ~= 0 then
        room:doIndicate(player.id, {to})
        to = room:getPlayerById(to)
        if to:isWounded() then
          room:recover({
            who = to,
            num = 1,
            recoverBy = player,
            skillName = self.name
          })
        end
      else
        player:drawCards(1, self.name)
      end
    else
      player:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.BeforeCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self, true) then
      for _, move in ipairs(data) do
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            return true
          end
        end
        if move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      move.extra_data = move.extra_data or {}
      move.extra_data.fengxiang = getFengxiangPlayer(player.room)
    end
  end,
}
liuyong:addSkill(zhuning)
liuyong:addSkill(fengxiang)
Fk:loadTranslationTable{
  ["steam__liuyong"] = "刘永",
  ["#steam__liuyong"] = "甘陵王",
  ["designer:steam__liuyong"] = "笔枔",
  ["illustrator:steam__liuyong"] = "黯荧岛工作室",

  ["steam__zhuning"] = "诛佞",
  [":steam__zhuning"] = "出牌阶段限一次，你可以交给一名其他角色任意张牌，这些牌标记为“隙”，然后你可以视为使用一张不计次数的【杀】或伤害类锦囊牌，"..
  "然后若此牌没有造成伤害，此技能本阶段改为“出牌阶段限两次”。",
  ["steam__fengxiang"] = "封乡",
  [":steam__fengxiang"] = "锁定技，当你受到伤害后，手牌中“隙”唯一最多的角色回复1点体力（没有唯一最多的角色则改为你摸一张牌）；"..
  "当有角色因手牌数改变而使“隙”唯一最多的角色改变后，你摸一张牌。",
  ["@@zhuning-inhand"] = "隙",
  ["#zhuning"] = "诛佞：交给一名角色任意张牌（标记为“隙”），然后视为使用一张伤害牌",
  ["#zhuning-use"] = "诛佞：你可以视为使用一张不计次数的伤害牌",

  ["$steam__zhuning1"] = "吾父之基业，岂能亡于奸宦之手！",
  ["$steam__zhuning2"] = "纵与吾兄成隙，亦当除此蛀虫！",
  ["$steam__fengxiang1"] = "百年扶汉积万骨，十载相隙累半生。",
  ["$steam__fengxiang2"] = "一骑蓝翎魏旨到，王兄大梦可曾闻？",
  ["~steam__liuyong"] = "刘公嗣！你睁开眼看看这八百里蜀川吧！",
}


local yanfuren = General(extension, "steam__yanfuren", "han", 3, 3, General.Female)
local channi_viewas = fk.CreateViewAsSkill{
  name = "steam__channi_viewas",
  anim_type = "offensive",
  pattern = "duel",
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip and #selected < Self:getMark("steam__channi")
  end,
  view_as = function(self, cards)
    if #cards == 0 then return end
    local card = Fk:cloneCard("duel")
    card:addSubcards(cards)
    card.skillName = "steam__channi_viewas"
    return card
  end,
}
local channi = fk.CreateActiveSkill{
  name = "steam__channi",
  anim_type = "support",
  prompt = "#steam__channi-active",
  min_card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local n = #effect.cards
    room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, self.name, nil, false, player.id)
    room:setPlayerMark(target, self.name, n)
    local success, data = room:askForUseActiveSkill(target, "steam__channi_viewas", "#steam__channi-invoke:"..player.id.."::"..n, true, {}, false)
    room:setPlayerMark(target, self.name, 0)
    if success then
      local card = Fk:cloneCard("duel")
      card.skillName = self.name
      card:addSubcards(data.cards)
      local use = {
        from = target.id,
        tos = table.map(data.targets, function(id) return {id} end),
        card = card,
        extra_data = {channi_data = {player.id, target.id, #data.cards}}
      }
      room:useCard(use)
    end
  end,
}
local channi_delay = fk.CreateTriggerSkill{
  name = "#steam__channi_delay",
  events = {fk.Damage, fk.Damaged},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player.dead and target and not target.dead and data.card and not data.chain and
    table.contains(data.card.skillNames, channi.name) then
      local room = player.room
      local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if not card_event then return false end
      local use = card_event.data[1]
      if use.extra_data then
        local channi_data = use.extra_data.channi_data
        if channi_data and channi_data[1] == player.id and channi_data[2] == target.id then
          self.cost_data = channi_data[3]
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      room:notifySkillInvoked(player, channi.name, "drawcard")
      room:doIndicate(player.id, {target.id})
      room:drawCards(target, self.cost_data, channi.name)
    else
      room:notifySkillInvoked(player, channi.name, "negative")
      local n = player:getHandcardNum()
      room:askForDiscard(player, n, n, false, channi.name, false)
    end
  end
}

local nifu = fk.CreateTriggerSkill{
  name = "steam__nifu",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Finish and player:getHandcardNum() ~= 3
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(self.name)
    local room = player.room
    local n = player:getHandcardNum() - 3
    if n < 0 then
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(-n, self.name)
    else
      room:notifySkillInvoked(player, self.name, "negative")
      room:askForDiscard(player, n, n, false, self.name, false)
    end
  end,
}
Fk:addSkill(channi_viewas)
channi:addRelatedSkill(channi_delay)
yanfuren:addSkill(channi)
yanfuren:addSkill(nifu)
Fk:loadTranslationTable{
  ["steam__yanfuren"] = "严夫人",
  ["#steam__yanfuren"] = "霜天薄裳",
  ["illustrator:steam__yanfuren"] = "君桓文化",
  ["steam__channi"] = "谗逆",
  [":steam__channi"] = "出牌阶段限一次，你可以交给一名其他角色任意张手牌，然后该角色可以将X张手牌当一张【决斗】使用（X至多为你以此法交给其的牌数）。"..
  "其因此使用【决斗】造成伤害后，其摸X张牌；其因此使用【决斗】受到伤害后，你弃置所有手牌。",
  ["steam__nifu"] = "匿伏",
  [":steam__nifu"] = "锁定技，一名角色的结束阶段，你将手牌摸至或弃置至三张。",
  ["steam__channi_viewas"] = "谗逆",
  ["#steam__channi_delay"] = "谗逆",
  ["#steam__channi-active"] = "发动 谗逆，将任意数量的手牌交给一名角色",
  ["#steam__channi-invoke"] = "谗逆：你可以将至多%arg张手牌当一张【决斗】使用<br>若对目标造成伤害你摸等量牌，若你受到伤害则 %src 弃置所有手牌",

  ["$steam__channi1"] = "宫、顺素不和，将军不在，此二人必难同心守城！",
  ["$steam__channi2"] = "将军可信者唯掌上戟、堂中妻，切不可信顺、宫之流！",
  ["$steam__nifu1"] = "我等一介弱女子，衣不当甲、手不掌兵，唯祈将军庇护。",
  ["$steam__nifu2"] = "吾所愿者，非夫得高官厚禄，乃君可四季长安。",
  ["~steam__yanfuren"] = "乱世浮萍，问归乡何处？",
}

local zhaoxiang = General(extension, "steam__zhaoxiang", "han", 4, 4, General.Female)

local fanghun = fk.CreateTriggerSkill{
  name = "steam__fanghun",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@meiying")
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@meiying", 0)
  end,
}
local fuhan = fk.CreateTriggerSkill{
  name = "steam__fuhan",
  events = {fk.TurnStart},
  frequency = Skill.Limited,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("@meiying") > 0 and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__fuhan-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getMark("@meiying")
    room:setPlayerMark(player, "@meiying", 0)
    room:handleAddLoseSkills(player, "-steam__fanghun")
    if player.dead then return end

    local generals, same_g = {}, {}
    for _, general_name in ipairs(room.general_pile) do
      same_g = Fk:getSameGenerals(general_name)
      table.insert(same_g, general_name)
      same_g = table.filter(same_g, function (g_name)
        local general = Fk.generals[g_name]
        return general.kingdom == "shu" or general.subkingdom == "shu" or general.kingdom == "han" or general.subkingdom == "han"
      end)
      if #same_g > 0 then
        table.insert(generals, table.random(same_g))
      end
    end
    if #generals == 0 then return false end
    generals = table.random(generals, n)

    local skills = {}
    local choices = {}
    for _, general_name in ipairs(generals) do
      local general = Fk.generals[general_name]
      local g_skills = {}
      for _, skill in ipairs(general.skills) do
        if #skill.attachedKingdom == 0 or
          (table.contains(skill.attachedKingdom, "shu") and player.kingdom == "shu") or
          (table.contains(skill.attachedKingdom, "han") and player.kingdom == "han") then
          table.insertIfNeed(g_skills, skill.name)
        end
      end
      for _, s_name in ipairs(general.other_skills) do
        local skill = Fk.skills[s_name]
        if #skill.attachedKingdom == 0 or
          (table.contains(skill.attachedKingdom, "shu") and player.kingdom == "shu") or
          (table.contains(skill.attachedKingdom, "han") and player.kingdom == "han") then
          table.insertIfNeed(g_skills, skill.name)
        end
      end
      table.insertIfNeed(skills, g_skills)
      if #choices == 0 and #g_skills > 0 then
        choices = {g_skills[1]}
      end
    end
    if #choices > 0 then
      local result = player.room:askForCustomDialog(player, self.name,
      "packages/aaa_fenghou/qml/ChooseGeneralSkillsBox.qml", {
        generals, skills, 1, 2, "#steam__fuhan-choice", false
      })
      if result ~= "" then
        choices = json.decode(result)
      end
      room:handleAddLoseSkills(player, table.concat(choices, "|"), nil)
    end
  end,
}
zhaoxiang:addSkill(fanghun)
zhaoxiang:addSkill(fuhan)
Fk:loadTranslationTable{
  ["steam__zhaoxiang"] = "赵襄",
  ["#steam__zhaoxiang"] = "月痕芳影",
  ["illustrator:steam__zhaoxiang"] = "疾速K",

  ["steam__fanghun"] = "芳魂",
  [":steam__fanghun"] = "当你使用【杀】指定目标后或成为【杀】的目标后，你获得1个“梅影”标记。",
  ["steam__fuhan"] = "扶汉",
  [":steam__fuhan"] = "限定技，回合开始时，你可以移去所有“梅影”标记并失去“芳魂”，然后从X张（X为移去“梅影”标记数）汉或蜀汉势力武将牌中选择"..
  "并获得至多两个技能。",

  --["#steam__fanghun"] = "芳魂：弃1枚“梅影”标记发动“龙胆”并摸一张牌",
  --["#steam__fanghun_trigger"] = "芳魂",
  ["@meiying"] = "梅影",
  ["#steam__fuhan-invoke"] = "扶汉：你可以移去“梅影”标记，获得两个蜀汉势力武将的技能！",
  ["#steam__fuhan-choice"] = "扶汉：选择你要获得的至多2个技能",

  ["$steam__fanghun1"] = "凝傲雪之梅为魄，英魂长存，独耀山河万古明！",
  ["$steam__fanghun2"] = "铸凌霜之寒成剑，青锋出鞘，斩尽天下不臣贼！",
  ["$steam__fuhan1"] = "逝者如斯，亘古长流，唯英烈之魂悬北斗而长存！",
  ["$steam__fuhan2"] = "赵氏之女，跪祈诸公勿渡黄泉，暂留人间、佑大汉万年！",
  ["~steam__zhaoxiang"] = "世受国恩，今当以身殉国。",
}


local shitao = General(extension, "steam__shitao", "qun", 4)

--- 获取被废除的装备栏
---@param player Player
local function getSealedEquipSlot(player)
  local all_slots = {"WeaponSlot", "ArmorSlot", "DefensiveRideSlot", "OffensiveRideSlot", "TreasureSlot"}
  return table.filter(all_slots, function(slot) return table.contains(player.sealedSlots, slot) end)
end

local jieqiu = fk.CreateActiveSkill{
  name = "steam__jieqiu",
  anim_type = "control",
  prompt = "#steam__jieqiu",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and #getSealedEquipSlot(Fk:currentRoom():getPlayerById(to_select)) == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local num = #target:getCardIds(Player.Equip)
    room:abortPlayerArea(target, target.equipSlots)
    if not target.dead then
      room:setPlayerMark(target, "@steam__jieqiu", player.general)
      room:setPlayerMark(target, "_steam__jieqiu", player.id)
      target:drawCards(num, self.name)
    end
  end,
}

local jieqiu_delay = fk.CreateTriggerSkill{
  name = "#steam__jieqiu_delay",
  events = {fk.EventPhaseEnd, fk.TurnEnd},
  anim_type = "control",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target:getMark("_steam__jieqiu") == 0 or target.dead then return end
    if event == fk.EventPhaseEnd then
      if target == player and target.phase == Player.Discard then
        local num = 0
        player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
          for _, move in ipairs(e.data) do
            if move.from == target.id and move.moveReason == fk.ReasonDiscard then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                  num = num + 1
                end
              end
            end
          end
          return false
        end, Player.HistoryPhase)
        if num > 0 then
          self.cost_data = num
          return true
        end
      end
    elseif target:getMark("_steam__jieqiu") == player.id and not player.dead then
      return player:usedSkillTimes(self.name, Player.HistoryRound) == 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return event == fk.EventPhaseEnd or player.room:askForSkillInvoke(player, self.name, data, "#steam__jieqiu-ask")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseEnd then
      local num = self.cost_data
      local all_choices = getSealedEquipSlot(player)
      if #all_choices > 0 then
        local choices = room:askForChoices(player, all_choices, num, num, self.name, "#steam__jieqiu-choice:::" .. num, false)
        room:resumePlayerArea(player, choices)
      end
    else
      room:doIndicate(player.id, {target.id})
      room:notifySkillInvoked(player, self.name, "control")
      player:broadcastSkillInvoke("steam__jieqiu")
      player:gainAnExtraTurn()
    end
  end,

  refresh_events = {fk.AreaResumed},
  can_refresh = function(self, event, target, player, data)
    return player == target and #getSealedEquipSlot(player) == 0 and player:getMark("_steam__jieqiu") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@steam__jieqiu", 0)
    room:setPlayerMark(player, "_steam__jieqiu", 0)
  end,
}
jieqiu:addRelatedSkill(jieqiu_delay)

local enchou = fk.CreateActiveSkill{
  name = "steam__enchou",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#steam__enchou",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and #getSealedEquipSlot(Fk:currentRoom():getPlayerById(to_select)) > 0 and to_select ~= Self.id
    and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local cids = target:getCardIds(Player.Hand)
    local cards, _ = U.askforChooseCardsAndChoice(player, cids, {"steam__enchou_get"}, self.name, "#steam__enchou-ask::" .. target.id)
    room:obtainCard(player, cards[1], false, fk.ReasonPrey, player.id, self.name)
    if not target.dead and not player.dead then
      local choices = getSealedEquipSlot(target)
      if #choices > 0 then
        local choice = room:askForChoice(player, choices, self.name, "#steam__enchou-choice::" .. target.id, false)
        room:resumePlayerArea(target, {choice})
      end
    end
  end,
}

shitao:addSkill(jieqiu)
shitao:addSkill(enchou)

Fk:loadTranslationTable{
  ["steam__shitao"] = "石韬",
  ["#steam__shitao"] = "快意恩仇",
  ["illustrator:steam__shitao"] = "鱼仔",

  ["steam__jieqiu"] = "劫囚",
  [":steam__jieqiu"] = "出牌阶段限一次，你可选择一名所有装备栏均未被废除的其他角色，废除其所有装备栏，然后其摸X张牌（X为废除前其装备区里的牌数）。其弃牌阶段结束时，其恢复等同于此阶段弃置手牌数量的装备栏。其回合结束时，若仍有装备栏被废除，则你可执行一个额外回合（每轮限一次）。",
  ["steam__enchou"] = "恩仇",
  [":steam__enchou"] = "出牌阶段限一次，你可观看一名有装备栏被废除的其他角色的手牌并获得其中一张牌，然后你恢复其一个装备栏。",

  ["#steam__jieqiu"] = "劫囚：废除一名其他角色所有装备栏",
  ["@steam__jieqiu"] = "被劫囚",
  ["#steam__jieqiu_delay"] = "劫囚",
  ["#steam__jieqiu-choice"] = "劫囚：恢复 %arg 个装备栏",
  ["#steam__jieqiu-ask"] = "劫囚：你可执行一个额外回合",

  ["#steam__enchou"] = "恩仇：观看一名有装备栏被废除的其他角色的手牌并获得一张牌，再恢复其一个装备栏",
  ["steam__enchou_get"] = "获得",
  ["#steam__enchou-ask"] = "恩仇：获得 %dest 一张手牌，然后恢复其一个装备栏",
  ["#steam__enchou-choice"] = "恩仇：恢复 %dest 一个装备栏",

  ["$steam__jieqiu1"] = "元直莫慌，石韬来也！",
  ["$steam__jieqiu2"] = "一群鼠辈，焉能挡我等去路！",
  ["$steam__enchou1"] = "江湖快意，恩仇必报！",
  ["$steam__enchou2"] = "今日之因，明日之果！",
  ["~steam__shitao"] = "想不到竟中了官府的埋伏……",
}

local xuelingyun = General(extension, "steam__xuelingyun", "wei", 3, 3, General.Female)
local xialei = fk.CreateTriggerSkill{
  name = "steam__xialei",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:getMark("steam__xialei-round") > 2 then return false end
    local room = player.room
    local move_event = room.logic:getCurrentEvent()
    local parent_event = move_event.parent
    local card_ids = {}
    if parent_event ~= nil then
      if parent_event.event == GameEvent.UseCard or parent_event.event == GameEvent.RespondCard then
        local parent_data = parent_event.data[1]
        if parent_data.from == player.id then
          card_ids = room:getSubcardsByRule(parent_data.card)
        end
      elseif parent_event.event == GameEvent.Pindian then
        local pindianData = parent_event.data[1]
        if pindianData.from == player then
          card_ids = room:getSubcardsByRule(pindianData.fromCard)
        else
          for toId, result in pairs(pindianData.results) do
            if player.id == toId then
              card_ids = room:getSubcardsByRule(result.toCard)
              break
            end
          end
        end
      end
    end
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
            Fk:getCardById(info.cardId).color == Card.Red then
              return true
            end
          end
        elseif #card_ids > 0 then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.Processing and table.contains(card_ids, info.cardId) and
            Fk:getCardById(info.cardId).color == Card.Red then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = U.turnOverCardsFromDrawPile(player, 3 - player:getMark("steam__xialei-round"), self.name, false)
    if #ids == 1 then
      room:obtainCard(player, ids, false, fk.ReasonJustMove, player.id, self.name)
    else
      local to_return, choice = U.askforChooseCardsAndChoice(player, ids, {"steam__xialei_top", "steam__xialei_bottom"},
      self.name, "#steam__xialei-chooose")
      room:obtainCard(player, to_return, false, fk.ReasonJustMove, player.id, self.name)
      U.returnCardsToDrawPile(player, ids, self.name, choice == "steam__xialei_top", false)
    end
    room:addPlayerMark(player, "steam__xialei-round", 1)
  end,
}
local anzhi = fk.CreateActiveSkill{
  name = "steam__anzhi",
  anim_type = "support",
  prompt = "#steam__anzhi",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:getMark("steam__anzhi-phase") == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:addPlayerMark(player, "steam__anzhi-phase", 1)
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if player.dead then return end
    if judge.card.color == Card.Red then
      room:setPlayerMark(player, "steam__xialei-round", 0)
    elseif judge.card.color == Card.Black and #room:getBanner("@$CenterArea") > 0 then
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(room.current), Util.IdMapper), 1, 1,
        "#steam__anzhi-choose", self.name, true)
      if #to > 0 then
        to = room:getPlayerById(to[1])
        local cards = U.askforChooseCardsAndChoice(to, room:getBanner("@$CenterArea"), {"OK"}, self.name, "#steam__anzhi-prey")
        room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonJustMove, self.name, nil, true, to.id)
      end
    end
  end,
}
local anzhi_trigger = fk.CreateTriggerSkill{
  name = "#steam__anzhi_trigger",
  anim_type = "masochism",
  events = {fk.Damaged},
  main_skill = anzhi,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(anzhi)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__anzhi")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("steam__anzhi")
    anzhi:onUse(room, {
      from = player.id,
      cards = {},
      tos = {},
    })
    room:removePlayerMark(player, "steam__anzhi-phase", 1)
  end,
}
anzhi.CenterArea = true
anzhi:addRelatedSkill(anzhi_trigger)
xuelingyun:addSkill(xialei)
xuelingyun:addSkill(anzhi)
Fk:loadTranslationTable{
  ["steam__xuelingyun"] = "薛灵芸",
  ["#steam__xuelingyun"] = "锦织翠鸾",
  ["designer:steam__xuelingyun"] = "",
  ["illustrator:steam__xuelingyun"] = "匪萌十月",

  ["steam__xialei"] = "霞泪",
  [":steam__xialei"] = "当你的红色牌进入弃牌堆后，你可以观看牌堆顶三张牌，获得其中一张并可将其余牌置于牌堆底，然后你本轮以此法观看的牌数-1。",
  ["steam__anzhi"] = "暗织",
  [":steam__anzhi"] = "出牌阶段限一次或当你受到伤害后，你可以判定：若结果为红色，你重置〖霞泪〗的观看牌数；若结果为黑色，你可以令一名非当前回合角色从中央区获得一张牌。",
  ["#steam__xialei-chooose"] = "霞泪：选择一张卡牌获得",
  ["steam__xialei_top"] = "将剩余牌置于牌堆顶",
  ["steam__xialei_bottom"] = "将剩余牌置于牌堆底",
  ["#steam__anzhi"] = "暗织：你可以判定，若为红色重置〖霞泪〗，若为黑色令一名非当前回合角色获得中央区一张牌",
  ["#steam__anzhi-choose"] = "暗织：你可以令一名非当前回合角色获得中央区一张牌",
  ["#steam__anzhi-prey"] = "暗织：获得中央区一张牌",
  ["#steam__anzhi_trigger"] = "暗织",

  ["$steam__xialei1"] = "彩车过郦桥，青鹊可衔吾泪还常山。",
  ["$steam__xialei2"] = "昔我往矣，杨柳依依，今我来思，玉壶盛泪。",
  ["$steam__anzhi1"] = "行织者凭灵台慧眼，故而暗室可织。",
  ["$steam__anzhi2"] = "我曾织衣数千，可闭目行穿针引线。",
  ["~steam__xuelingyun"] = "手织锦绣千里，唯不见归途。",
}


local godxunyu = General(extension, "steam__godxunyu", "god", 3)
Fk:loadTranslationTable{
  ["steam__godxunyu"] = "神荀彧",
  ["#steam__godxunyu"] = "洞心先识",
  ["cv:steam__godxunyu"] = "",
  ["designer:steam__godxunyu"] = "先帝",
  ["illustrator:steam__godxunyu"] = "JJGG",
  ["~steam__godxunyu"] = "宁鸣而死，不默而生……",
}

local tianzuo = fk.CreateTriggerSkill{
  name = "steam__tianzuo",
  anim_type = "control",
  events = {fk.GameStart, fk.PreCardEffect, fk.CardEffecting},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.PreCardEffect then
      return data.to == player.id and data.card.trueName == "raid_and_frontal_attack"
    elseif event == fk.CardEffecting then
      return data.from ~= player.id and data.card.trueName == "raid_and_frontal_attack"
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local name = "rfenghou__raid_and_frontal_attack"
      local derivecards = {{name, Card.Spade, 2}, {name, Card.Spade, 4}, {name, Card.Spade, 6}, {name, Card.Spade, 8},
      {name, Card.Club, 3},{name, Card.Club, 5},{name, Card.Club, 7},{name, Card.Club, 9}}
      for _, info in ipairs(derivecards) do
        local id = room:printCard(info[1], info[2], info[3]).id
        if room:getCardArea(id) == Card.Void then
          table.removeOne(room.void, id)
          table.insert(room.draw_pile, math.random(1, #room.draw_pile), id)
          room:setCardArea(id, Card.DrawPile, nil)
        end
      end
      room:syncDrawPile()
      room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
    elseif event == fk.CardEffecting then
      local to = room:getPlayerById(data.to)
      if to.dead then return end
      room:doIndicate(player.id, {data.to})
      local cards = to:getCardIds("h")
      if #cards > 0 then
        U.viewCards(player, cards, self.name, "$ViewCardsFrom:"..to.id)
      end
      local choice = room:askForChoice(player, { "RFA_frontal", "RFA_raid" }, self.name,
      "#steam__tianzuo-choice:" .. data.from..":"..data.to)
      data.extra_data = data.extra_data or {}
      data.extra_data.RFAChosen = choice

    else
      return true
    end
  end,
}
godxunyu:addSkill(tianzuo)

Fk:loadTranslationTable{
  ["steam__tianzuo"] = "天佐",
  [":steam__tianzuo"] = "锁定技，游戏开始时，将8张<a href='raid_and_frontal_attack_href'>【奇正相生】</a>加入牌堆；【奇正相生】对你无效；其他角色的【奇正相生】生效时，你观看目标手牌，并重新指定“正兵”、“奇兵”。",
  ["#steam__tianzuo-choice"] = "天佐：请重新指定：正兵：%dest不出闪，%src获得其牌；奇兵：%dest不出杀，%src对其造成伤害",

  ["raid_and_frontal_attack_href"] = "【<b>奇正相生</b>】（♠2/♠4/♠6/♠8/♣3/♣5/♣7/♣9） 锦囊牌<br/>" ..
  "出牌阶段，对一名其他角色使用。当此牌指定目标后，你为其指定“奇兵”或“正兵”。"..
  "目标角色可以打出一张【杀】或【闪】，然后若其为：“正兵”目标且未打出【杀】，你对其造成1点伤害；“奇兵”目标且未打出【闪】，你获得其一张牌。",
  
  ["$steam__tianzuo1"] = "此时进之多弊，守之多利，愿主公熟虑。",
  ["$steam__tianzuo2"] = "主公若不时定，待四方生心，则无及矣。",
}

local lingce = fk.CreateTriggerSkill{
  name = "steam__lingce",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    local zhinang = { "ex_nihilo", "dismantlement", "nullification" }
    return
      player:hasSkill(self) and
      (
        table.contains(zhinang, data.card.trueName) or
        table.contains(player:getTableMark("@$steam__dinghan"), data.card.trueName) or
        data.card.trueName == "raid_and_frontal_attack"
      )
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.card:isVirtual() or Fk:getCardById(data.card.id, true).name ~= data.card.name then
      player:drawCards(1, self.name)
      return
    end
    local targets = table.map(room.alive_players, Util.IdMapper)
    if #targets == 0 then return false end
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#steam__lingce-damage", self.name, false)
    if #tos > 0 then
      local to = room:getPlayerById(tos[1])
      room:doIndicate(player.id, {to.id})
      room:damage { from = player, to = to, damage = 1, skillName = self.name }
    end
  end,
}
godxunyu:addSkill(lingce)

Fk:loadTranslationTable{
  ["steam__lingce"] = "灵策",
  [":steam__lingce"] = "锁定技，当<a href='bag_of_tricks'>智囊</a>牌、〖定汉〗已记录的锦囊牌或【奇正相生】使用时，若为虚拟或转化牌，你摸一张牌；若为实体牌，你对一名角色造成1点伤害。",
  ["bag_of_tricks"] = "#\"<b>智囊</b>\" ：即【过河拆桥】【无懈可击】【无中生有】。",
  ["#steam__lingce-damage"] = "灵策：对一名角色造成1点伤害",

  ["$steam__lingce1"] = "绍士卒虽众，其实难用，必无为也。",
  ["$steam__lingce2"] = "袁军不过一盘砂砾，主公用奇则散。",
}


local steam__dinghan = fk.CreateTriggerSkill{
  name = "steam__dinghan",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) then
      return false
    end

    if event == fk.TargetConfirming then
      return data.from ~= player.id and
        data.card.type == Card.TypeTrick and
        data.card.trueName ~= "raid_and_frontal_attack" and
        not table.contains(player:getTableMark("@$steam__dinghan"), data.card.trueName)
    else
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      local room = player.room

      local dinghanRecord = player:getTableMark("@$steam__dinghan")
      local allTricksName = {}
      for _, id in ipairs(Fk:getAllCardIds()) do
        local card = Fk:getCardById(id)
        if card.type == Card.TypeTrick and not card.is_derived and not table.contains(dinghanRecord, card.trueName) then
          table.insertIfNeed(allTricksName, card.trueName)
        end
      end

      local choices, cardName = {"Cancel"}, nil
      if #allTricksName > 0 then
        table.insert(choices, 1, "steam__dinghan_addRecord")
      end
      if #dinghanRecord > 0 then
        table.insert(choices, 2, "steam__dinghan_removeRecord")
      end
      local choice = room:askForChoice(player, choices, self.name)

      if choice == "Cancel" then return false end
      if choice == "steam__dinghan_addRecord" then
        cardName = table.random(allTricksName)
      else
        cardName = room:askForChoice(player, dinghanRecord, self.name)
      end

      self.cost_data = { choice = choice, cardName = cardName }
    end

    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local record = player:getTableMark("@$steam__dinghan")
    if event == fk.TargetConfirming then
      table.insert(record, data.card.trueName)
      room:setPlayerMark(player, "@$steam__dinghan", record)
      AimGroup:cancelTarget(data, player.id)
      return true
    else
      local costData = self.cost_data
      if costData.choice == "steam__dinghan_addRecord" then
        table.insert(record, costData.cardName)
      else
        table.removeOne(record, costData.cardName)
      end
      room:setPlayerMark(player, "@$steam__dinghan", #record > 0 and record or 0)
    end
  end,
}
godxunyu:addSkill(steam__dinghan)

Fk:loadTranslationTable{
  ["steam__dinghan"] = "定汉",
  [":steam__dinghan"] = "当你成为其他角色使用锦囊牌的目标时，若此牌牌名未被记录，则记录之并取消此目标；回合开始时，你可以移除或随机增加一种锦囊牌的牌名记录。",
  ["@$steam__dinghan"] = "定汉",
  ["steam__dinghan_addRecord"] = "随机增加牌名",
  ["steam__dinghan_removeRecord"] = "移除牌名",

  ["$steam__dinghan1"] = "杀身有地，报国有时。",
  ["$steam__dinghan2"] = "益国之事，虽死弗避。",
}


local simazhao = General(extension, "steam__simazhao", "jin", 3)
Fk:loadTranslationTable{
  ["steam__simazhao"] = "司马昭",
  ["#steam__simazhao"] = "嘲风开天",
  ["designer:steam__simazhao"] = "先帝",
  ["illustrator:steam__simazhao"] = "鬼画府",
}

local suzhi = fk.CreateTriggerSkill{
  name = "steam__suzhi",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.CardUsing, fk.DamageCaused, fk.AfterCardsMove, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) and player == player.room.current then
      if event == fk.CardUsing then
        return target == player and data.card.type == Card.TypeTrick
      elseif event == fk.DamageCaused then
        return target == player and not data.chain
      elseif event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.from and move.from ~= player.id and move.moveReason == fk.ReasonDiscard then
            --FIXME:没算同时两名角色弃置牌的情况，鸽
            local from = room:getPlayerById(move.from)
            if from and not (from.dead or from:isNude()) then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                  self.cost_data = move.from
                  return true
                end
              end
            end
          end
        end
      elseif event == fk.TurnEnd then
        return player:usedSkillTimes(self.name) < 3
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.TurnEnd then
      room:notifySkillInvoked(player, self.name, "control")
      room:setPlayerMark(player, "@@steam__suzhi_fankui", 1)
      room:handleAddLoseSkills(player, "efengqi__fankui", self.name)
    else
      if event == fk.CardUsing then
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:drawCards(1, self.name)
      elseif event == fk.DamageCaused then
        room:notifySkillInvoked(player, self.name, "offensive")
        room:doIndicate(player.id, {data.to.id})
        data.damage = data.damage + 1
      elseif event == fk.AfterCardsMove then
        room:notifySkillInvoked(player, self.name, "control")
        local card = room:askForCardChosen(player, room:getPlayerById(self.cost_data), "he", self.name)
        room:obtainCard(player.id, card, false, fk.ReasonPrey, player.id, self.name)
      end
    end
  end,
}

local suzhi_delay = fk.CreateTriggerSkill{
  name = "#steam__suzhi_delay",
  mute = true,
  events = {fk.TurnStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@steam__suzhi_fankui") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@steam__suzhi_fankui", 0)
    room:handleAddLoseSkills(player, "-efengqi__fankui", suzhi.name)
  end,
}
suzhi:addRelatedSkill(suzhi_delay)

local suzhi_targetmod = fk.CreateTargetModSkill{
  name = "#steam__suzhi_targetmod",
  frequency = Skill.Compulsory,
  bypass_distances = function(self, player, skill, card)
    return card and player:hasSkill(suzhi) and player.phase ~= Player.NotActive and
    card.type == Card.TypeTrick
  end,
}
suzhi:addRelatedSkill(suzhi_targetmod)
simazhao:addSkill(suzhi)
simazhao:addRelatedSkill("efengqi__fankui")

Fk:loadTranslationTable{
  ["steam__suzhi"] = "夙智",
  [":steam__suzhi"] = "锁定技，回合内：1.你造成的伤害+1；2.使用锦囊牌无距离限制且你摸一张牌；3.当其他角色的牌因弃置而置入弃牌堆时，你获得其一张牌。回合结束时，若你本回合触发以上效果不足三次，直到你的下个回合开始，你拥有〖反馈〗。",
  ["@@steam__suzhi_fankui"] = "反馈",
  ["#steam__suzhi_delay"] = "夙智",
  
  ["$steam__suzhi1"] = "敌军势大与否，无碍我自计定施。",
  ["$steam__suzhi2"] = "汝竭力强攻，也只是徒燥军心。",
}

local zhaoxin = fk.CreateTriggerSkill{
  name = "steam__zhaoxin",
  anim_type = "control",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__zhaoxin-ask")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:showCards(player.player_cards[Player.Hand])
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return (p:getHandcardNum() <= player:getHandcardNum()) end), Util.IdMapper)
    if #targets > 0 then
      local to = room:getPlayerById(room:askForChoosePlayers(player, targets, 1, 1, "#steam__zhaoxin-choose", self.name, false)[1])
      U.swapHandCards(room, player, player, to, self.name)
    end
  end,
}
simazhao:addSkill(zhaoxin)

Fk:loadTranslationTable{
  ["steam__zhaoxin"] = "昭心",
  [":steam__zhaoxin"] = "当你受到伤害后，你可以展示所有手牌，然后与一名手牌数不大于你的其他角色交换手牌。",
  ["#steam__zhaoxin-ask"] = "昭心：你可以展示所有手牌，然后与一名手牌数不大于你的角色交换手牌",
  ["#steam__zhaoxin-choose"] = "昭心：选择一名手牌数不大于你的角色，与其交换手牌",
  
  ["$steam__zhaoxin1"] = "行明动正，何惧他人讥毁。",
  ["$steam__zhaoxin2"] = "大业之举，岂因宵小而动？",
}

simazhao:addSkill("steam__fuyu")

local panjun = General(extension, "steam__panjun", "wu", 3)
local guanwei = fk.CreateTriggerSkill{
  name = "steam__guanwei",
  anim_type = "support",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target.phase == Player.Play and not target.dead and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and not player:isNude() then
      local x = 0
      local suit = nil
      player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data[1]
        if use.from == target.id then
          if suit == nil then
            suit = use.card.suit
          elseif suit ~= use.card.suit then
            x = 0
            return true
          end
          x = x + 1
        end
      end, Player.HistoryTurn)
      return x > 1
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#steam__guanwei-invoke::"..target.id, true)
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:throwCard(self.cost_data.cards, self.name, player, player)
    if not target.dead then
      target:drawCards(2, self.name)
      target:gainAnExtraPhase(Player.Play)
    end
  end,
}
panjun:addSkill(guanwei)
local gongqing = fk.CreateTriggerSkill{
  name = "steam__gongqing",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.from then
      return data.from:getAttackRange() < 3 and data.damage > 1
    end
  end,
  on_use = function(self, event, target, player, data)
    data.damage = 1
  end,
}
local gongqing2 = fk.CreateTriggerSkill{
  name = "#steam__gongqing_defense",
  anim_type = "defensive",
  priority = 0,
  main_skill = gongqing,
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(gongqing) and data.from then
      return data.from:getAttackRange() < 3 and data.damage > 1
    end
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(gongqing.name, 2)
    data.damage = 1
  end,
}
gongqing:addRelatedSkill(gongqing2)
panjun:addSkill(gongqing)
Fk:loadTranslationTable{
  ["steam__panjun"] = "潘濬",
  ["#steam__panjun"] = "方严疾恶",
  ["illustrator:steam__panjun"] = "秋呆呆",

  ["steam__guanwei"] = "观微",
  [":steam__guanwei"] = "每回合限一次，一名角色的出牌阶段结束时，若其于此回合内使用过的牌数大于1且这些牌花色均相同或均没有花色，"..
  "你可弃置一张牌。令其摸两张牌，获得一个额外的出牌阶段。",

  ["steam__gongqing"] = "公清",
  [":steam__gongqing"] = "锁定技，当你受到大于1点伤害时，若来源的攻击范围小于3，你将伤害值改为1。",
  ["#steam__guanwei-invoke"] = "观微：你可以弃置一张牌，令 %dest 摸两张牌并执行一个额外的出牌阶段",
  ["#steam__gongqing_defense"] = "公清",

  ["$steam__guanwei1"] = "今日宴请诸位，有要事相商。",
  ["$steam__guanwei2"] = "天下未定，请主公以大局为重。",
  ["$steam__gongqing1"] = "尔辈何故与降虏交善。",
  ["$steam__gongqing2"] = "豪将在外，增兵必成祸患啊！",
  ["~steam__panjun"] = "耻失荆州，耻失荆州啊！",
}


local liuyan = General(extension, "steam__liuyan", "qun", 3)
local tushe = fk.CreateTriggerSkill{
  name = "steam__tushe",
  anim_type = "drawcard",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.firstTarget and
      not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).type == Card.TypeBasic end) and
      #AimGroup:getAllTargets(data.tos) > 0
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(#AimGroup:getAllTargets(data.tos), self.name)
  end,
}
local limu = fk.CreateActiveSkill{
  name = "steam__limu",
  anim_type = "offensive",
  prompt = "#steam__limu",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return not player:hasDelayedTrick("indulgence") and not table.contains(player.sealedSlots, Player.JudgeSlot)
  end,
  target_filter = Util.FalseFunc,
  card_filter = function(self, to_select, selected, player)
    local c = Fk:getCardById(to_select)
    if #selected == 0 and (c.suit == Card.Diamond or (c.suit == Card.Heart and c.name == "jink")) then
      local card = Fk:cloneCard("indulgence")
      card:addSubcard(to_select)
      return not player:prohibitUse(card) and not player:isProhibited(player, card)
    end
  end,
  on_use = function(self, room, use)
    local player = room:getPlayerById(use.from)
    local cards = use.cards
    local card = Fk:cloneCard("indulgence")
    card:addSubcards(cards)
    room:useCard{
      from = use.from,
      tos = {{use.from}},
      card = card,
    }
    if not player.dead then
      room:recover{
        who = player,
        num = 1,
        skillName = self.name
      }
    end
  end,
}
local limu_refresh = fk.CreateTriggerSkill{
  name = "#steam__limu_refresh",

  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    return player == target and #player:getCardIds(Player.Judge) > 0 and player:hasSkill(limu)
  end,
  on_refresh = function(self, event, target, player, data)
    data.extraUse = true
  end,
}
local limu_targetmod = fk.CreateTargetModSkill{
  name = "#steam__limu_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:hasSkill(limu) and #player:getCardIds(Player.Judge) > 0
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return card and player:hasSkill(limu) and #player:getCardIds(Player.Judge) > 0
  end,
}
limu:addRelatedSkill(limu_refresh)
limu:addRelatedSkill(limu_targetmod)
liuyan:addSkill(tushe)
liuyan:addSkill(limu)
Fk:loadTranslationTable{
  ["steam__liuyan"] = "刘焉",
  ["#steam__liuyan"] = "裂土之宗",
  ["cv:steam__liuyan"] = "金垚",
  ["designer:steam__liuyan"] = "桃花僧",
  ["illustrator:steam__liuyan"] = "明暗交界", -- 传说皮 雄踞益州
  ["steam__tushe"] = "图射",
  [":steam__tushe"] = "当你使用指定目标后，若你没有基本牌，则你可以摸X张牌（X为此牌指定的目标数）。",
  ["steam__limu"] = "立牧",
  [":steam__limu"] = "出牌阶段，你可以将一张<font color='red'>♦</font>牌或<font color='red'>♥</font>【闪】当【乐不思蜀】对自己使用，然后回复1点体力；你的判定区有牌时，你使用牌没有次数和距离限制。",

  ["#steam__limu"] = "立牧：选择一张<font color='red'>♦</font>牌或<font color='red'>♥</font>【闪】当【乐不思蜀】对自己使用，然后回复1点体力",

  ["$steam__tushe1"] = "据险以图进，备策而施为！",
  ["$steam__tushe2"] = "夫战者，可时以奇险之策而图常谋！",
  ["$steam__limu1"] = "今诸州纷乱，当立牧以定！",
  ["$steam__limu2"] = "此非为偏安一隅，但求一方百姓安宁！",
  ["~steam__liuyan"] = "我怎会有图谋不轨之心？",
}

return extension
